import {commonWordList, queryDetailAddress,} from "@/api/system";

interface OrderStatus {
    label: string;
    value: number
}

export function useCommonData() {
    const queryCommonArea = (queryString: string) => {
        return new Promise((resolve, reject) => {
            commonWordList({ keys: queryString })
                .then(res => {
                    resolve(res.result);
                })
                .catch(err => {
                    reject(err);
                });
        });
    };
    const queryUserDetailAddress = async (lat: number,lnt: number) => {
        await queryDetailAddress({ lat, lnt }).then(res => {
            return res.result;
        });
    };

    const handleOrderStatus = (orderType: number) => {
        let orderStatusList: OrderStatus[] = [
            {label: "待支付", value: 0},
            {label: "已支付", value: 1},
            {label: "处理中", value: 2},
            {label: "代发货", value: 3},
            {label: "运输中", value: 4},
            {label: "已取消", value: 5},
            {label: "已完成", value: 6},
            {label: "退款中", value: 7},
            {label: "已关闭", value: 8},
            {label: "待确认", value: 9},
            {label: "已确认", value: 10},
            {label: "已入住", value: 11},
            {label: "待处理", value: 12},
            {label: "已退款", value: 13},
            {label: "已过期", value: 14},
            {label: "售后处理中", value: 15},
            {label: "推送中", value: 20},
            {label: "推送失败", value: 21},
            {label: "待使用", value: 22},
        ];
        let orderStatusListIndex = orderStatusList.findIndex((item: OrderStatus) => item.value === orderType);
        console.log(orderStatusListIndex,'indexOb');
        if(orderStatusListIndex < 0){
            return "未知状态";
        }
        return orderStatusList[orderStatusListIndex].label;
    };

    return {
        queryCommonArea,
        queryUserDetailAddress,
        handleOrderStatus
    };


}